home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok24.lha
/
TurboFiles
/
asm
/
TurboWrite.asm
< prev
next >
Wrap
Assembly Source File
|
1993-08-15
|
5KB
|
153 lines
;Assemblerversion of the Procedure WriteBytes from the Module TurboFiles
;Created: 10.6.89 by
; Stefan Salewski
; Stolper Weg 3
; 2160 Stade
;-------------------------------------------------------------------
;The Modula-procedure-header:
;PROCEDURE WriteBytes(VAR f{10}:File;adr{11}:ADDRESS;len{7}:LONGINT);
;-------------------------------------------------------------------
;TYPE
;Result=(notOpen,done,notdone,openError,readError,writeError,seekError,
; endOfFile,outOfMem,tooManyFiles);
notOpen EQU 0
done EQU 1
notDone EQU 2
openError EQU 3
readError EQU 4
writeError EQU 5
seekError EQU 6
endOfFile EQU 7
outOfMem EQU 8
tooManyFile EQU 9
;-------------------------------------------------------------------
;Modes of Dos.Seek
Dos_beginning EQU -1
Dos_current EQU 0
Dos_end EQU 1
;-------------------------------------------------------------------
;The Modula-Datastructure:
;File=RECORD
; fhPtr:Dos.FileHandlePtr;
; dosBase:ADDRESS;
; base:ADDRESS;
; top:ADDRESS;
; filePos:LONGINT;
; startLength:LONGINT;
; act:CharPtr;
; readTop:ADDRESS;
; writeBase:ADDRESS;
; writeTop:ADDRESS;
; res:Result;
; END;
;The offsets in the File-Variable:
_fhPtr EQU 0
_dosBase EQU 4
_base EQU 8
_top EQU 12
_filePos EQU 16
_startLength EQU 20
_act EQU 24
_readTop EQU 28
_writeBase EQU 32
_writeTop EQU 36
_res EQU 40
;-------------------------------------------------------------------
;The offsets of the Dos-functions:
_Seek EQU -66
_Write EQU -48
_Read EQU -42
;-------------------------------------------------------------------
; We can use all registers except A4, A5 (and A7 of course)
; A0, A1, D0, D1 are not resistent against changes by Dos-Funktions,
; and I changes than too by myself.
; I don't use D0 and D1 as registerparameters in the ProcedureHaeder,
; because they are used to evaluate the Procedure-parameters.
;-------------------------------------------------------------------
;The variables f, adr and len I get from the Modula program
;in the registers
f EQUR A2; ADDRESS (The address of the file-variable)
adr EQUR A3; VALUE (The address to take the data from)
tempAct EQUR D4;
copyOfBase EQUR D5; The Values top and base (of the buffer) are constant,
copyOfTop EQUR D6; so I copy them to registers to have quicker access.
len EQUR D7; VALUE (How many bytes to read)
;-------------------------------------------------------------------
START:
CMPI.B #done,_res(f)
BNE TheEnd
TST.L len
BLE TheEnd
MOVE.L _top(f),copyOfTop
MOVE.L _base(f),copyOfBase;
MOVE.L _act(f),tempAct
CMP.L _writeTop(f),copyOfBase
BNE.S MainLoop
MOVE.L tempAct,_writeBase(f)
MainLoop:
CMP.L tempAct,copyOfTop
BGT.S BufferNotFull
InitBuffer:
CMP.L _writeTop(f),copyOfBase
BEQ.S BufferNotChanged
SaveBuffer:
MOVE.L _writeBase(f),D2
SUB.L _readTop(f),D2
MOVEQ #Dos_Current,D3
MOVE.L _fhPtr(f),D1
MOVE.L _dosBase(f),A6
JSR _Seek(A6)
MOVE.L _writeTop(f),D3
SUB.L _writeBase(f),D3
MOVE.L _fhPtr(f),D1
MOVE.L _writeBase(f),D2
;MOVE.L _dosBase(f),A6; not necessary
JSR _Write(A6)
CMP.L D0,D3
BNE.S WriteErr
MOVE.L tempAct,D2
SUB.L _writeTop(f),D2
BEQ.S NoSeek
MOVE.L _fhPtr(f),D1
MOVEQ #Dos_Current,D3
JSR _Seek(A6)
NoSeek:
MOVE.L tempAct,D0
SUB.L _readTop(f),D0
ADD.L D0,_filePos(f)
MOVE.L copyOfBase,_writeTop(f)
BufferNotChanged:
MOVE.L copyOfBase,_writeBase(f)
MOVE.L copyOfBase,tempAct
MOVE.L copyOfBase,_readTop(f)
BufferNotFull:
MOVE.L copyOfTop,D0
SUB.L tempAct,D0
CMP.L len,D0
BLE.S ok
MOVE.L len,D0
ok:
SUB.L D0,len
SUBQ.L #1,D0
MOVE.L tempAct,A0
CopyLoop:
MOVE.B (adr)+,(A0)+
DBRA D0,CopyLoop
MOVE.L A0,tempAct
MOVE.L A0,_writeTop(f)
TST.L len
BNE MainLoop
MOVE.L tempAct,_act(f)
RTS
WriteErr:
MOVE.B #writeError,_res(f)
TheEnd:
MOVE.L tempAct,_act(f)
RTS
END